package com.hy.mydesktop.client.mvc.core.builder;

import java.util.HashMap;
import java.util.Map;

import com.hy.erp.inventory.pojo.interfaces.IDepot;
import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtAppEventType;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.ItemOfAssociateToWindow;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceParameter;

public class PanelInFormBuilderTemplate {

	public static GxtComponentControllerMetaNodeModel createFormPanelBuilderTemplate(
			Map<String, Object> map1, Map<String, Object> panelInFormMap2) {
		Map<String, Object> sumFormPanelController=new HashMap<String, Object>();
		sumFormPanelController.put("component_controller_model_type", ComponentControllerEnum.CONTENTPANEL_CONTROLLER_MODEL);
		sumFormPanelController.put("component_controller_model_type_index", ComponentControllerEnum.CONTENTPANEL_CONTROLLER_MODEL.ordinal());
		
		

		GxtComponentControllerMetaNodeModel node45=new GxtComponentControllerMetaNodeModel(sumFormPanelController);
		node45 = ControllerAndComponentMetaNodeModelCreationTemplate.buildCommonAttributes(node45,map1);
		if (map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="panelInFormController_"+controllerMetaModelId;
			node45.setId(id);
			node45.setControllerMetaNodeModelId(id);
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		
		panelInFormMap2.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, node45.getControllerMetaNodeModelId());
		GxtComponentMetaNodeModel gxtComponentMetaNodeModel =getPanelInFormGxtComponentMetaNodeModel(panelInFormMap2);
		node45.setGxtComponentMetaNodeModel(gxtComponentMetaNodeModel);
		
		return node45;

	}

	

	private static GxtComponentMetaNodeModel getPanelInFormGxtComponentMetaNodeModel(
			Map<String, Object> map2) {
//		map2.put("id", "02_01_contentPanel_Depot");	
		
		Map<String, Object> formPanelMap=new HashMap<String, Object>();
		formPanelMap.put("component_model_type", ComponentTypeEnum.CONTENTPANEL_MODEL);
		formPanelMap.put("component_model_type_index", ComponentTypeEnum.CONTENTPANEL_MODEL.ordinal());
		formPanelMap.put("layoutdatainparentcontainer", ".5");
//		formPanelMap.put("autowidth", true);
//		formPanelMap.put("autoheight", true);
//		formPanelMap.put("width", 400);
//		formPanelMap.put("height", 100);
		formPanelMap.put("title", "panelInForm");	

		formPanelMap.put("frame", true);
		formPanelMap.put("headervisible", false);
		formPanelMap.put("layoutindex", ComponentTypeEnum.FORMLAYOUT_MODEL.ordinal());
		//TODO FormPanelHandler.configureFormPanel ( MaxPanel );
		//FormPanelHandler.configureFormPanel ( MaxPanel );
		for (String key : map2.keySet()) {
			formPanelMap.put(key, map2.get(key));
		}
		GxtComponentMetaNodeModel node5=new GxtComponentMetaNodeModel(formPanelMap);
		if (map2.get(MetaDataConstants.FORM_ID)!=null) {
			node5.setId(map2.get(MetaDataConstants.FORM_ID).toString());
		} else {

			if (map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
				String controllerMetaModelId=(String)map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
				String id="panelInFormGxtComponent_"+controllerMetaModelId;
				node5.setId(id);
			}else {
				throw new RuntimeException("xxxxxxxxxxxxx");
			}
		}
		
		
		node5 =ControllerAndComponentMetaNodeModelCreationTemplate.removeUnusedProperties(node5);

		return node5;
	}



	public static ItemOfAssociateToWindow createTextFieldItem(String entityPropertyName,String fieldlabel,
			String emptytext) {
		Map<String, Object> textField01 = new HashMap<String, Object>();			
	    textField01.put("component_model_type_index", ComponentTypeEnum.TEXTFIELD_MODEL.ordinal()); 		    							
		textField01.put("width", "100");
		textField01.put("title", ComponentTypeEnum.TEXTFIELD_MODEL.toString());
		textField01.put("fieldlabel", fieldlabel);
//		textField01.put("fieldlabel", "仓库名称");
		textField01.put("name", "textField01");
//		textField01.put("emptytext", "请输入仓库名称");
		textField01.put("emptytext", emptytext);
		textField01.put("allowblank", true);
//	    textField01.put("id", Idepot.DEPOTNAME);
	    textField01.put("id", entityPropertyName);
//	    simpleComboBox01.put("id", "positon.positionType");
//	    simpleComboBox01.put("id", "province");
	    ItemOfAssociateToWindow itemOfAssociateToWindow  = new ItemOfAssociateToWindow(textField01);
//	    String springComponentName =gridColumnId+"Service";
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter("provinceService", "getAllPersistentEntities" );
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter(springComponentName, "getAllPersistentEntities" );
//	    gxtToSeamServiceParameter.setMethodArgumentsType(null);
//	    item.setGxtToSeamServiceParameter(gxtToSeamServiceParameter);
	    itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));

	    
	    return itemOfAssociateToWindow;

	}

	public static ItemOfAssociateToWindow createComboxItem(String entityPropertyName,String fieldlabel){
		return createComboxItem(entityPropertyName, fieldlabel, null);
	}


	public static ItemOfAssociateToWindow createComboxItem(String entityPropertyName,String fieldlabel,
			String emptytext) {
		Map<String, Object> textField01 = new HashMap<String, Object>();			
	    textField01.put("component_model_type_index", ComponentTypeEnum.COMBOBOX_MODEL.ordinal()); 		    							
		textField01.put("width", "100");
		textField01.put("title", ComponentTypeEnum.COMBOBOX_MODEL.toString());
		textField01.put("fieldlabel", fieldlabel);
//		textField01.put("fieldlabel", "仓库名称");
		textField01.put("name", "comboBox");
//		textField01.put("emptytext", "请输入仓库名称");
//		type.put("fieldlabel", "仓库类型");
		textField01.put("emptytext", "===请选择===");
//		textField01.put("emptytext", emptytext);
		textField01.put("allowblank", true);
//	    textField01.put("id", Idepot.DEPOTNAME);
	    textField01.put("id", entityPropertyName);
		//type.put("dataload", "xxx");
	    textField01.put("typeahead", true);
	    textField01.put("loadingtext", "数据加载中,请稍等。。。。。。");
	    ItemOfAssociateToWindow itemOfAssociateToWindow  = new ItemOfAssociateToWindow(textField01);
	    String springComponentName =entityPropertyName+"Service";
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter("provinceService", "getAllPersistentEntities" );
	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter(springComponentName, "getAllPersistentEntities" );
	    gxtToSeamServiceParameter.setMethodArgumentsType(null);
	    itemOfAssociateToWindow.setGxtToSeamServiceParameter(gxtToSeamServiceParameter);
	    itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));

	    
	    return itemOfAssociateToWindow;
	}



	public static ItemOfAssociateToWindow createDateFieldItem(String entityPropertyName,String fieldlabel,
			String emptytext) {
		Map<String, Object> textField01 = new HashMap<String, Object>();			
	    textField01.put("component_model_type_index", ComponentTypeEnum.DATEFIELD_MODEL.ordinal()); 		    							
		textField01.put("width", "100");
		textField01.put("title", ComponentTypeEnum.DATEFIELD_MODEL.toString());
		textField01.put("fieldlabel", fieldlabel);
//		textField01.put("fieldlabel", "仓库名称");
		textField01.put("name", "dateField02");
//		textField01.put("emptytext", "请输入仓库名称");
		textField01.put("emptytext", emptytext);
		textField01.put("allowblank", true);
//	    textField01.put("id", Idepot.DEPOTNAME);
	    textField01.put("id", entityPropertyName);

	    ItemOfAssociateToWindow itemOfAssociateToWindow  = new ItemOfAssociateToWindow(textField01);
//	    String springComponentName =gridColumnId+"Service";
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter("provinceService", "getAllPersistentEntities" );
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter(springComponentName, "getAllPersistentEntities" );
//	    gxtToSeamServiceParameter.setMethodArgumentsType(null);
//	    item.setGxtToSeamServiceParameter(gxtToSeamServiceParameter);
	    itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));

	    
	    return itemOfAssociateToWindow;
	}



	public static ItemOfAssociateToWindow createCheckBoxItem(String entityPropertyName,String fieldlabel
			) {
		Map<String, Object> textField01 = new HashMap<String, Object>();			
	    textField01.put("component_model_type_index", ComponentTypeEnum.CHECKBOX_MODEL.ordinal()); 		    							
		textField01.put("width", "100");
		textField01.put("title", ComponentTypeEnum.CHECKBOX_MODEL.toString());
		textField01.put("fieldlabel", fieldlabel);
		textField01.put("boxlabel", fieldlabel);
//		textField01.put("boxlabel", "是否允许负库存");

		textField01.put("value", true);
//		textField01.put("fieldlabel", "仓库名称");
		textField01.put("name", "check1");
		//   checkBox01.put ( "id" , "depot.LOSSSTOCK" );
//	    textField01.put("id", Idepot.DEPOTNAME);
	    textField01.put("id", entityPropertyName);
	    textField01.put("typeahead", true);
	    ItemOfAssociateToWindow itemOfAssociateToWindow  = new ItemOfAssociateToWindow(textField01);
//	    String springComponentName =entityPropertyName+"Service";
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter("provinceService", "getAllPersistentEntities" );
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter(springComponentName, "getAllPersistentEntities" );
//	    gxtToSeamServiceParameter.setMethodArgumentsType(null);
//	    itemOfAssociateToWindow.setGxtToSeamServiceParameter(gxtToSeamServiceParameter);
	    itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));

	    
	    return itemOfAssociateToWindow;
	}



	public static ItemOfAssociateToWindow createTextAreaItem(String entityPropertyName,String fieldlabel,
			String emptytext) {
		
		Map<String, Object> textField01 = new HashMap<String, Object>();			
	    textField01.put("component_model_type_index", ComponentTypeEnum.TEXTAREA_MODEL.ordinal()); 		    							
		textField01.put("title", ComponentTypeEnum.TEXTAREA_MODEL.toString());
		textField01.put("fieldlabel", fieldlabel);
   		textField01.put("label", fieldlabel);
   		textField01.put("width", 400);
   		textField01.put("height", 100);
//		textField01.put("fieldlabel", "仓库名称");
		textField01.put("name", "textArea");
//		textField01.put("emptytext", "请输入仓库名称");
//		type.put("fieldlabel", "仓库类型");
		textField01.put("allowblank", true);
//	    textField01.put("id", Idepot.DEPOTNAME);
	    textField01.put("id", entityPropertyName);
		textField01.put("emptytext", emptytext);
		textField01.put("allowblank", true);
	    textField01.put("typeahead", true);
	    ItemOfAssociateToWindow itemOfAssociateToWindow  = new ItemOfAssociateToWindow(textField01);
//	    String springComponentName =entityPropertyName+"Service";
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter("provinceService", "getAllPersistentEntities" );
//	    GxtToSeamServiceParameter gxtToSeamServiceParameter=new GxtToSeamServiceParameter(springComponentName, "getAllPersistentEntities" );
//	    gxtToSeamServiceParameter.setMethodArgumentsType(null);
//	    itemOfAssociateToWindow.setGxtToSeamServiceParameter(gxtToSeamServiceParameter);
	    itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.COMPONENT_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));

	    
	    return itemOfAssociateToWindow;

	}



	
	
	
}
